#include "main_interface.h"
#include "create_connection.h"

#include <QApplication>

#include "student_information_dialog.h"
#include "teacher_information_dialog.h"

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    //连接数据库
    if (!CreateConnection()){
        return 1;
    }

    MainInterface mainInterface;
    StudentInformationDialog studentInformationDialog;
    TeacherInformationDialog teacherInformationDialog;

    ////主界面------>其他界面
    //--->学生信息修改界面
    QObject::connect(&mainInterface, &MainInterface::p0_show2AlterStudentInformationDialog,
                     &studentInformationDialog, &StudentInformationDialog::initializeAlterStudentInformationDialog);

    //--->学生信息新增界面
    QObject::connect(&mainInterface, &MainInterface::p0_show2InsertStudentInformationDialog,
                     &studentInformationDialog, &StudentInformationDialog::initializeInsertStudentInformationDialog);

    //--->教师信息修改界面
    QObject::connect(&mainInterface, &MainInterface::p0_show2AlterTeacherInformationDialog,
                     &teacherInformationDialog, &TeacherInformationDialog::initializeAlterTeacherInformationDialog);

    //--->教师信息新增界面
    QObject::connect(&mainInterface, &MainInterface::p0_show2InsertTeacherInformationDialog,
                     &teacherInformationDialog, &TeacherInformationDialog::initializeInsertTeacherInformationDialog);


    ////其他界面------>主界面
    //学生信息界面到--->信息管理界面
    QObject::connect(&studentInformationDialog, &StudentInformationDialog::studentInformationDialog2MainInterface,
                     &mainInterface, &MainInterface::p0_searchTableData);

    QObject::connect(&teacherInformationDialog, &TeacherInformationDialog::teacherInformationDialog2MainInterface,
                     &mainInterface, &MainInterface::p0_searchTableData);

    mainInterface.show();

    return a.exec();
}
